﻿using Application.AppService.IConfig;
using AutoMapper;
using Domain.Entity.Config;
using Domain.Repository.IConfig;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers.MoKuaiYi_第一个模块_.resume_management_简历管理_
{
    public class ERController : Controller
    {
        private readonly IConfig_public_charAppService cPCAppService;
        private readonly IMapper mapper;
        private readonly IEngage_resumeAppService eRAppService;
        private readonly IWebHostEnvironment webHostEnvironment;

        public ERController(IConfig_public_charAppService cPCAppService, IMapper mapper, IEngage_resumeAppService eRAppService, IWebHostEnvironment webHostEnvironment)
        {
            this.cPCAppService = cPCAppService;
            this.mapper = mapper;
            this.eRAppService = eRAppService;
            this.webHostEnvironment = webHostEnvironment;
        }
        public IActionResult Index()
        {
            return View();
        }
        
        
        
        [HttpPost("GetCPCSSSAttributeKind")]
        public async Task<IActionResult> GetCPCSSSAttributeKind(string name)
        {
            List<Config_public_char> cpc=await cPCAppService.GetCPCAttributeKindAsync(name);
            return Json(cpc);
        }

        [HttpPost("AddER")]
        public async Task<IActionResult> AddER(Engage_resume er)
        {
            bool rs=await eRAppService.AddERAsync(er);
            return Json(rs);
        }


        [HttpPost]
        public IActionResult Upload2(IFormFileCollection file)
        {
            string name1 = "";
            foreach (var item in file)
            {
                //生成文件名
                string name = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                //获取后缀名
                string ext = item.FileName.Substring(item.FileName.LastIndexOf('.'));
                //设置上传路径
               
                string path = $"wwwroot/images/" + name + ext;
                //Core生成文件的绝对路径
                var jpath = Path.Combine(webHostEnvironment.ContentRootPath, path);
                //创建上传文件对应的文件夹
                (new FileInfo(jpath)).Directory.Create();
                using (FileStream stream = new FileStream(jpath, FileMode.CreateNew))
                {
                    item.CopyTo(stream);//图片上传
                                        //TempData["name"] = name + ext;//保存图片的值
                }
                name1 = name + ext;

            }
            return Content(name1);
        }

    }
}
